Go to Home Page
Questions?
Call 1-800-572-5517
 
  Go to Home Page  
  See all products
  See price schedules
  See manuals, tutorials, articles
  Download a free 30-day trial
  See user testimonials
  About Pacific Systems Group
 
 
SMF Tools
  See SMF Record Layouts
  See Sample SMF Reports
  Learn How to Export SMF Data
  Download Free SMF Reporting Software (30 days)
 
One of the greatest SMF record parsing programming languages I've ever seen. Chief, Large Systems Services Branch, NIH
  Choose Spectrum Writer to add 4GL to your product
  Report Writer Speedup Tips Article
Spectrum SMF Writer - the 4GL SMF Report Writer.

Add customized reports and PC export files to your product!

Table of Contents

NOTE: you can find this and other lessons in a
more complete and viewable format (including all Figures) in our Tutorial PDF.

Lesson 7. How to Create Your Own Fields

  1. This lesson teaches you how to create your own fields to use in a report. The control statement discussed is:
  2. the COMPUTE statement
  3. Sometimes the data you need for a report is not in the SMF record. Yet the data might be easily computed from one or more fields which are in the record. In such cases, simply create a new field with a COMPUTE statement.
Creating Numeric Fields
  1. A COMPUTE statement specifies the name of a new field to create and supplies a computational expression to assign a value to that field. The complete rules for computational expressions are discussed in . Basically, your expression will consist of one or more arithmetic operations performed with SMF fields and/or literals.
  2. For example, refer back to the report in Figure _. That report has two numeric columns -- the EXCP block count ( SMF30BLK ) and the maximum block size ( SMF30BSZ ). We could compute our own new field called "maximum EXCP bytes" by multiplying those two fields together:

COMPUTE: MAX-EXCP-BYTES = SMF30BLK * SMF30BSZ

  1. Now that the MAX-EXCP-BYTES field has been created, we can use that field in any way that other fields can be used. For example, a computed field can be used: as a column in the body of the report; in the report titles; as a sort field; as a control break field; as part of a conditional expression (in the INCLUDEIF statement); or even as an operand in a subsequent COMPUTE statement to create another field.
  2. Figure _ shows a report that uses the above COMPUTE statement.
  3. Computing your own fields for a report
    Computing your own fields for a report
    +
  4. You can perform addition, subtraction, multiplication, and division in the COMPUTE statement. Use the +, -, * and / symbols, respectively. You may also use parentheses as needed to indicate the order in which the operations should be performed.
  5. since dashes are allowed as characters in field names, when performing subtraction, always put a blank space before and after the minus sign. Otherwise, the minus sign will be treated as part of the field name. Blanks are optional around the other arithmetic operators.
  6. In addition to these arithmetic operations, there are also a large number of built-in functions that you can use in the COMPUTE statement. These built-in functions allow you to perform more complex operations on SMF data. A complete list of built-in functions is found in .
  7.  
  8. COMPUTE statements usually come after the INPUT statement, so that you can refer to fields from the input file. And your COMPUTE statement must appear before any control statement that uses the field being created. Beyond that, the precise location of a COMPUTE statement is not important. The contents of a COMPUTE field is calculated once for each new record from the input file.
Technical Discussion: When is the Computation Actually Performed?
  1. (Feel free to skip over this section if you like.) Since Spectrum SMF Writer's language is non-procedural, the exact location of a COMPUTE statement does not affect when, or even whether, the computation is actually performed for a given input record.
  2. For efficiency's sake, Spectrum SMF Writer performs computations only if or when the value of the field is actually needed. In that sense, the COMPUTE statement is similar to the FIELD statement. Both statements describe how to obtain the contents of a given field. (The FIELD statement tells where the raw data is located in the input record, and what format it is in; the COMPUTE statement tells what formula to use to calculate the value of a field.) But Spectrum SMF Writer itself decides when and whether it actually needs to go to the effort of obtaining a field's value while producing the report.
  3. For example, assume that a COMPUTE field is used in the COLUMNS statement, but is not referred to in the INCLUDEIF statement. If the INCLUDEIF statement fails for an input record, Spectrum SMF Writer will not need to calculate the COMPUTE field's value at all for that record. It only needs to compute the value if the record passes the INCLUDEIF statement's conditions (so that the data can be shown in the output line).
  4. For this reason, it is fine to store commonly used COMPUTE statements right in the copy library along with a file definition. They will not add any (significant) overhead to report runs that do not actually use them.
Creating Time Fields
  1. When working with SMF files, time data plays an important role. You can calculate useful information from the time stamps (and time intervals) contained in many SMF records.
  2. For example, the SMF 30 record has two CPU time fields named SMF30UCT (total TCB time) and SMF30UCS (total SRB time). We can use a COMPUTE statement to create a new CPU time field containing the combined SRB and TCB time. We just add the two time fields together, like this:

COMPUTE: TOTAL-CPU-TIME = SMF30UCT + SMF30UCS

  1. The report in Figure _ uses the above statement.
  2. The TOTAL-CPU-TIME field created in this statement is a time field. So by default it is formatted in the report as HH:MM:SS.DD . If you find that you are dealing with very small time intervals, (like the 00:00:00.24 in Figure _, you may prefer to view the data as a numeric number of seconds. Use the #MAKENUM built-in function to change the value from a time field to a numeric field.

COMPUTE: CPU-SECONDS = #MAKENUM(TOTAL-CPU-TIME)

  1. When times are converted to numeric values, the result is the total number of seconds contained in the time field. The report in now shows this computed field as a numeric value (0.24).
Calculating Elapsed Times
  1. Let's look at another example of computing time fields. When working with SMF data, it is often useful to calculate the time difference between two time fields. Let's say that we want to show a job's total elapsed run time. There is no field in the SMF 30 record that contains the elapsed time. However, we can compute it by calculating the difference between two time-of-day fields that are present in SMF 30 (subtype 5) records. SMF30SIT is the time of day that the initiator selected the job. And SMF30TME is the time that SMF logged the termination of the job.
  2. So it might seem tempting to just compute the elapsed time like this

COMPUTE: JOB-ELAPSED-TIME = SMF30TME - SMF30SIT

  1. However, this simple method has an obvious drawback. It won't work if the job runs past midnight and ends on the next day. (The time difference will be negative). The correct way to compute this elapsed time is to also take into account the dates when the job began and ended. The job initiation date is in SMF30STD . And the SMF log date is in SMF30DTE . Now armed with these four fields, Spectrum SMF Writer's powerful built-in functions make the calculation easy:

COMPUTE: JOB-ELAPSED-SECONDS =
(#MAKENUM(SMF30DTE) * 86400 + #MAKENUM(SMF30TME))
- (#MAKENUM(SMF30STD) * 86400 + #MAKENUM(SMF30SIT))

  1. The statement above creates a field that contains the number of elapsed seconds that a job ran. (It does this by converting both the start date/time and the end date/time into their total number of seconds since the beginning of the nineteenth century, and then subtracting the starting value from the ending value.) Figure _ in the next chapter Figure _ shows a report that uses this COMPUTE statement.
  2. If you prefer to see the elapsed time in regular HH:MM:SS time format, you can convert this numeric seconds field to a time field, like this:

COMPUTE: JOB-ELAPSED-TIME = #MAKETIME(JOB-ELAPSED-SECONDS)

  1. Figure _ also shows this computed field.
Creating Character Fields
  1. You can also create character fields. There is only one operation used in computing character fields -- the concatenation operation. The plus sign (+) is used as the symbol for concatenation. Of course, there are also many built-in functions that operate on and/or return character data.
  2. Here is an example of a character field that is handy for reports from many SMF record types, including type 14.

COMPUTE: SMF14-JOBID = SMF14JBN
+ ' ' + #FORMAT(SMF14RSD)
+ ' ' + #FORMAT(SMF14RST)

  1. The above statement creates a single new field that has a unique value for every job in the SMF file. It concatenates the jobname with the date and time that the job hit the internal reader. This combination forms a unique identifier for the job, And this is very useful when you want to sort and break on all of the records for a single job -- perhaps printing a total line for the job. In fact, there is an example of using this field in just that way in Figure _.
  2. In the statement above, we used the #FORMAT built-in field in two places. This is necessary because you can only concatenate character fields. The #FORMAT function formats the date value in SMF14RSD into a MM/DD/YY character field. Similarly, we formatted the SMF30RST time field into a HH:MM:SS.DD character field.
  3. We also inserted blanks between these SMF fields to make the result more readable, in case we want to print it in the report.
  4. Here is one more example of using built-in fields to easily extract data that would take quite a few steps in a procedural language. We use the #REPLACE and #PARSE functions to extract just the first node of the DSNAME field from the SMF 14 record.

COMPUTE: FIRST-NODE = #PARSE(#REPLACE(SMF14_JFCBDSNM, '.', ' '), 1)

Summary
  1. Here is a summary of what we learned in this lesson:
  2. the COMPUTE statement is used to create new fields
  3. a simple COMPUTE statement assigns the result of a single computational expression to a new field
  4. The next lesson will introduce a more complex form of the COMPUTE statement.
To Learn More
  1. You can also learn:
  2. about many powerful built-in functions available in the COMPUTE statement, listed in
  3. how to specify the number of decimal places a numeric or time field should contain ()
  4. the complete syntax for the COMPUTE statement, in .
Copyright 2024.
Pacific Systems Group.
All rights reserved.
Home | Products | Prices | Documentation | 30-Day Trials | Customer Reviews | Company | FAQ | Sample Reports | SMF Records
Send Your Comments or Questions